package com.ruoyi.yljf.controller.AppController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.system.domain.vo.SysDictDataVO;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.yljf.domain.Article;
import com.ruoyi.yljf.domain.Table;
import com.ruoyi.yljf.domain.dto.ArticleDTO;
import com.ruoyi.yljf.domain.vo.ArticleTypeVO;
import com.ruoyi.yljf.domain.vo.ArticleVO;
import com.ruoyi.yljf.service.IArticleService;
import com.ruoyi.yljf.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 咨询文章Controller
 * 
 * @author metaee
 * @date 2025-02-13
 */
@Anonymous
@RestController
@RequestMapping("api/article")
public class ApiArticleController extends BaseController {
    @Autowired
    private IArticleService articleService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private TableService TableService;

    /**
     * 查询咨询文章列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArticleDTO articleDTO) {
        startPage();
        List<Article> list = articleService.selectArticleList(new Article(articleDTO));
        List<ArticleVO> listVO = articleService.typeConversion(list);
        return getDataTableInfo(listVO,list);
    }

    /**
     * 查询伊芦咨询info列表
     */
    @GetMapping("/queryArticle")
    public AjaxResult queryArticle() {
        //查询伊芦咨询info列表
        List<SysDictDataVO> secondaryType = dictDataService.selectDictDataList("article_typ");
        List<ArticleTypeVO> listVO = articleService.queryArticle(secondaryType);
        return success(listVO);
    }

    /**
     * 获取咨询文章详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(articleService.queryById(id));
    }

    /**
     * 查询标签管理列表
     */
    @GetMapping("/tableList")
    public TableDataInfo tablelist() {
        startPage();
        List<Table> list = TableService.list(new LambdaQueryWrapper<>(Table.class).orderByAsc(Table::getUseNum));
        return getDataTable(list);
    }

}
